from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from common.models import Product,Category
import os
def index(request):
    lists = Product.objects.all()
    for vo in lists:
        ty = Category.objects.get(id=category.id)
        vo.categoryname = ty.name
    context = {'productlist':lists}
    return render(request,"web/index.html",context)

def add(request,pid):
	ob = Product.objects.get(id=pid)
	pic =ob.toDict()
	pic['m'] =int(request,POST.get("m",1))
	prolist = request.session.get("prolist",{})

	if pid in prolist:
		prolist[pid][m]+=pic['m']
	else:
		prolist[pid] = pic
	request.session['prolist'] = prolist
	return redirect(reverse('cart_add'))


